package com.gkj.controller;

import com.gkj.blog.business.enums.ResponseStatus;
import com.gkj.blog.business.service.IpLogService;
import com.gkj.blog.business.vo.entity.PvUvVo;
import com.gkj.blog.framework.object.ResponseVO;
import com.gkj.blog.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/ipLog")
public class IpLogController {
    @Autowired
    IpLogService ipLogService;

    @PostMapping("getPvUvByTime")
    public ResponseVO getPvUvByTime(@DateTimeFormat(pattern ="yyyy-MM-dd HH:mm:ss") Date start,@DateTimeFormat(pattern ="yyyy-MM-dd HH:mm:ss") Date end){
        if(start==null||end==null){
            return ResultUtil.error("请选择正确的日期");
        }
        List<PvUvVo> pvUvs = ipLogService.getPvUv(start, end);
        if(pvUvs==null)
            return ResultUtil.error("没有访问记录");
        else
            return ResultUtil.success(null,pvUvs);
    }

    @PostMapping("getAreaPvUv")
    public ResponseVO getAreaPvUv(){
        List<Map> areaUV_pv = ipLogService.getAreaUV_PV();
        return ResultUtil.success(null,areaUV_pv);
    }

    @PostMapping("getHeapInfo")
    public ResponseVO getHeapInfo(){
        return ResultUtil.success(null,ipLogService.getHeapInfo());
    }

    @PostMapping("getSortPagePv")
    public ResponseVO getSortPagePv(){
        return ResultUtil.success(null,ipLogService.getSortPagePv(5));
    }

}
